package com.ruoyi.system.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ZtfSysUserbean;
import com.ruoyi.system.domain.dto.ZtfSysUserbeanDTO;
import com.ruoyi.system.result.PageResult;
import com.ruoyi.system.service.ZtfISysUserbeanService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户信息Controller
 * 
 * @author liupeng
 * @date 2025-06-06
 */
@RestController
@RequestMapping("/admin/system/userbean")
@Api(tags ="后台用户管理接口")
public class ZtfSysUserbeanController extends BaseController
{
    @Autowired
    private ZtfISysUserbeanService ztfISysUserbeanService;

    /**
     * 查询用户信息列表（系统生成的）
     */
//    @PreAuthorize("@ss.hasPermi('system:userbean:list')")
//    @GetMapping("/list")
//    @ApiOperation("用户列表")
//    public TableDataInfo list(ZtfSysUserbean ztfSysUserbean)
//    {
//        startPage();
//        List<ZtfSysUserbean> list = ztfISysUserbeanService.selectSysUserbeanList(ztfSysUserbean);
//        return getDataTable(list);
//    }

    /**
     * 导出用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:userbean:export')")
    @Log(title = "用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZtfSysUserbean sysUserbean)
    {
        List<ZtfSysUserbean> list = ztfISysUserbeanService.selectSysUserbeanList(sysUserbean);
        ExcelUtil<ZtfSysUserbean> util = new ExcelUtil<ZtfSysUserbean>(ZtfSysUserbean.class);
        util.exportExcel(response, list, "用户信息数据");
    }

    /**
     * 获取用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:userbean:query')")
    @GetMapping("/{userId}")
    @ApiOperation("获取用户信息详情")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(ztfISysUserbeanService.selectSysUserbeanByUserId(userId));
    }

    /**
     * 新增用户信息
     */
    @PreAuthorize("@ss.hasPermi('system:userbean:add')")
    @Log(title = "用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZtfSysUserbean sysUserbean)
    {
        return toAjax(ztfISysUserbeanService.insertSysUserbean(sysUserbean));
    }

    /**
     * 修改用户信息
     */
    @PreAuthorize("@ss.hasPermi('system:userbean:edit')")
    @Log(title = "用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改")
    public AjaxResult edit(@RequestBody ZtfSysUserbean sysUserbean)
    {
        return toAjax(ztfISysUserbeanService.updateSysUserbean(sysUserbean));
    }

    /**
     * 删除用户信息
     */
    @PreAuthorize("@ss.hasPermi('system:userbean:remove')")
    @Log(title = "用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    @ApiOperation("删除")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(ztfISysUserbeanService.deleteSysUserbeanByUserIds(userIds));
    }

    /**
     * 新的用户列表
     * @param ztfSysUserbeanDTO
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:userbean:list')")
    @GetMapping("/list")
    @ApiOperation("新的用户列表")
    public AjaxResult list(ZtfSysUserbeanDTO ztfSysUserbeanDTO)
    {
        //返回分页数据
        PageResult pageResult  = ztfISysUserbeanService.newSelectZtSysUserbeanList(ztfSysUserbeanDTO);
        return AjaxResult.success(pageResult);
    }
}
